
<template>
  <div class="dashboard-editor-container">

    <panel-group @handleSetLineChartData="handleSetLineChartData" />

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <el-col :span="12">
        <div class="chart-wrapper">
          <line-chart :chart-data="lineChartData" />
        </div>

      </el-col>

      <el-col :span="12">
        <div class="chart-wrapper">
          <line-chart :chart-data="lineChartData1" />
        </div>
      </el-col>

      <el-col :span="12">
        <div class="chart-wrapper">
          <line-chart :chart-data="lineChartData2" />
        </div>
      </el-col>

      <el-col :span="12">
        <div class="chart-wrapper">
          <line-chart :chart-data="lineChartData3" />
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import PanelGroup from './dashboard/PanelGroup'
import LineChart from './dashboard/LineChart'
import RaddarChart from './dashboard/RaddarChart'
import PieChart from './dashboard/PieChart'
import BarChart from './dashboard/BarChart'
import axios from "axios";

let dateData = "1";
const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    titleText:'用户量'

  },
  messages: {
    expectedData: [100, 300, 120, 144, 160, 130, 140],
    titleText:'矿机购买金额'


  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    titleText:'充值金额'

  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    titleText:'提现金额'

  }
}




export default {
  name: 'Index',
  dateData,
  components: {
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart,

  },
  mounted() {

    // 发ajax请求，用以获取数据， 测试
    //正式
    //const url = 'http://8.135.121.102:8083/data/config/statusic';

    //测试
    const url = 'http://127.0.0.1:9000/data/config/statusic';
    axios.get(url).then(
      response => {
        const result = response.data.data;

        lineChartData.newVisitis.expectedData = result.userCount;
        lineChartData.messages.expectedData = result.messageCount;
        lineChartData.purchases.expectedData = result.orderCount;
        lineChartData.shoppings.expectedData = result.priceCount;
        dateData = result.dateDate;

      }
    ).catch(
      response => {
        alert('系统繁忙!' + response);
      },
    );
  },
  data() {
    return {
      lineChartData: lineChartData.newVisitis,
      lineChartData1: lineChartData.messages,
      lineChartData2: lineChartData.purchases,
      lineChartData3: lineChartData.shoppings,
      dateData: dateData
    }
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type]
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>


